let MaskOverlay

function getMaskOverlay() {
  if (MaskOverlay) {
    return MaskOverlay
  }

  if (window.BMapGL?.Overlay) {
    MaskOverlay = function (point, className) {
      this._point = point

      if (className) {
        this._className = className
      }
    }

    MaskOverlay.prototype = new window.BMapGL.Overlay()

    MaskOverlay.prototype.initialize = function (map) {
      this._map = map
      let div = document.createElement('div')
      if (this._className) {
        div.className = this._className
      } else {
        div.className = 'mask'
      }
      map.getPanes().markerPane.append(div)
      this._div = div
      return div
    }
    MaskOverlay.prototype.draw = function () {
      // 设置蒙版宽高
      this._div.style.width = this._map.width + 'px'
      this._div.style.height = this._map.height + 'px'
      // this._div.style.background =
      //   'radial-gradient(circle at center,transparent,rgba(12,13,15,0.1),rgba(12,13,15,0.3),rgba(12,13,15,0.7),#0c0d0f 80%)'
    }

    MaskOverlay.prototype.show = function () {
      if (this._div) {
        this._div.style.display = ''
      }
    }
    MaskOverlay.prototype.hide = function () {
      if (this._div) {
        this._div.style.display = 'none'
      }
    }

    return MaskOverlay
  }

  return undefined
}

export default getMaskOverlay
